<?php
/* 运费管理
* @Author: Jerry-chen
* @Date:   2014-07-14 15:58:33
* @Last Modified time: 2014-07-14 16:41:57
* @Last Modified by: Jerry-chen<uranusbill@163.com>
* @ Copyright (c) 2014 http://www.cooldreamer.com All rightsreserved.
*/

class FareControl extends CommonControl
{
	public $model;
	/**
	 * [__auto 自动运行]
	 * @return [type] [description]
	 */
	public function __auto()
	{
		$this->model = K('Fare');
	}
	/**
	 * [index列表页]
	 * @return [type] [description]
	 */
	public function index()
	{
		// 查也所有的数据 
		$fareData = $this->model->get_all();
		//分配数据
		$this->assign('fareData',$fareData);
		$this->display();

	}
	/**
	 * [add 添加数据]
	 */
	public function add()
	{
		if(IS_POST)
		{
			// p(Q('post.'));
			$result =$this->model->add_();
			if($result){
				$this->success('添加成功','add');
			}
				$thid->error('添加失败','add');
		}
		$this->display();
	}
	/**
	 * [edit 修改]
	 * @return [type] [description]
	 */
	public function edit()
	{
		if(IS_POST)
		{
			$Faredata = array(
				'farecity'=>Q('post.farecity'),
				'fareprice'=>Q('post.fareprice'),
				'faredes'=>Q('post.faredes'),
				);
			$result = $this->model->edit(array('fareid'=>Q('post.fareid')),$Faredata);	
			if($result)
			{
			$this->success('修改成功','index');
			}else{
			$this->error('修改失败','index');
			}
		}
	//根据GETID，查出数据
		$fareData =current($this->model->all(array('fareid'=>Q('get.fareid'))));
		$this->assign('fareData',$fareData);
		$this->display();
	}
	/**
	 * [del 删除]
	 * @return [type] [description]
	 */
	public function del()
	{
		$result = $this->model->del_(array('fareid'=>Q('get.fareid')));
		if($result)
			{
			$this->success('删除成功','index');
			}else{
			$this->error('删除失败','index');
			}
	}
}